package com.mdd.common.mapper;

import com.mdd.common.core.basics.IBaseMapper;
import com.mdd.common.entity.IndexVisit;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * 首页浏览记录Mapper
 * @author panweiliang
 */
@Mapper
public interface IndexVisitMapper extends IBaseMapper<IndexVisit> {

    @Select("SELECT SUM(visit) FROM ls_index_visit WHERE delete_time IS NULL")
    Long getTotalVisitCount();


    @Select("SELECT IFNULL(SUM(visit), 0) FROM ls_index_visit WHERE create_time >= #{start} AND create_time <= #{end} AND delete_time IS NULL")
    Long getVisitCount(@Param("start") Long start, @Param("end") Long end);

    @Select("SELECT count(DISTINCT ip) FROM ls_index_visit WHERE delete_time IS NULL")
    Long getTotalUserVisitCount();

    @Select("SELECT count(DISTINCT ip) FROM ls_index_visit WHERE create_time >= #{start} AND create_time <= #{end} AND delete_time IS NULL")
    Long getTotalVisitCountByTimestamp(@Param("start") Long start, @Param("end") Long end);
}
